using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace FastFoodToNight.Models.Mapping
{
    public class ChiTietDDHMap : EntityTypeConfiguration<ChiTietDDH>
    {
        public ChiTietDDHMap()
        {
            // Primary Key
            this.HasKey(t => new { t.madondathang, t.masanpham });

            // Properties
            this.Property(t => t.madondathang)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.masanpham)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("ChiTietDDH");
            this.Property(t => t.madondathang).HasColumnName("madondathang");
            this.Property(t => t.masanpham).HasColumnName("masanpham");
            this.Property(t => t.soluong).HasColumnName("soluong");

            // Relationships
            this.HasRequired(t => t.DonDatHang)
                .WithMany(t => t.ChiTietDDHs)
                .HasForeignKey(d => d.madondathang);
            this.HasRequired(t => t.SanPham)
                .WithMany(t => t.ChiTietDDHs)
                .HasForeignKey(d => d.masanpham);

        }
    }
}
